package com.km.core.dto;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import com.km.core.json.CustomPropertyPreFilter;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * <p></p>
 * Created by zhezhiyong@163.com on 2017/4/26.
 */
@SuppressWarnings({"serial", "rawtypes", "unused"})
public class BaseDto extends LinkedHashMap<String, Object> implements Dto, Serializable {

    public static CustomPropertyPreFilter fastJsonFilter;

    static {
        fastJsonFilter = new CustomPropertyPreFilter(Lists.newArrayList("password", "apPassword", "OperPass"));
    }

    public BaseDto() {
    }

    public BaseDto(Map<? extends String, ?> m) {
        super(m);
    }

    @Override
    public Dto put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    @Override
    public Integer getAsInteger(String pStr) {
        Integer result = Ints.tryParse((String) get(pStr));
        if (null == result) return 0;
        return result;
    }

    @Override
    public Long getAsLong(String pStr) {
        return null;
    }

    @Override
    public String getAsString(String pStr) {
        if ("null".equals(String.valueOf(get(pStr)))) return "";
        return String.valueOf(get(pStr));
    }

    @Override
    public BigDecimal getAsBigDecimal(String pStr) {
        return null;
    }

    @Override
    public Date getAsDate(String pStr) {
        return null;
    }

    @Override
    @SuppressWarnings("unchecked")
    public <T> List<T> getAsList(String key) {
        return (List<T>) get(key);
    }

    @Override
    public Timestamp getAsTimestamp(String pStr) {
        return null;
    }

    @Override
    public Boolean getAsBoolean(String key) {
        return null;
    }

    @Override
    public List getDefaultAList() {
        return null;
    }

    @Override
    public void setDefaultAList(List pList) {

    }

    @Override
    public List getDefaultBList() {
        return null;
    }

    @Override
    public void setDefaultBList(List pList) {

    }

    @Override
    public String getDefaultJson() {
        return null;
    }

    @Override
    public void setDefaultJson(String jsonString) {

    }

    @Override
    public String toXml(String pStyle) {
        return null;
    }

    @Override
    public String toXml() {
        return null;
    }

    @Override
    public String toJson() {
        return JSON.toJSONString(this);
    }

    @Override
    public String toJsonFilter() {
        return JSON.toJSONString(this, BaseDto.fastJsonFilter);
    }

    @Override
    public void println() {

    }

    @Override
    public String toJson(String pFormat) {
        return null;
    }

    @Override
    public Date getAsDate(String pStr, String format) {
        return null;
    }

    @Override
    public Byte getAsByte(String pStr) {
        return null;
    }

    @Override
    public Integer getAsInteger(String pStr, int defaultValue) {
        return "null".equals(getAsString(pStr)) || Strings.isNullOrEmpty(getAsString(pStr)) ? defaultValue : Integer.valueOf(getAsString(pStr));
    }

    @Override
    public String getAsString(String pStr, String defaultValue) {
        return "null".equals(getAsString(pStr)) || Strings.isNullOrEmpty(getAsString(pStr)) ? defaultValue : getAsString(pStr);
    }

    @Override
    public Byte getAsByte(String pStr, byte defaultValue) {
        return null;
    }

    @Override
    public Double getAsDouble(String pStr) {
        return null;
    }

    @Override
    public Double getAsDouble(String pStr, Double defaultValue) {
        return null;
    }

    @Override
    public Dto getAsDto(String pStr) {
        return null;
    }

    @Override
    public List<Dto> getAsDtoList(String string) {
        return null;
    }
}
